
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using Reply.Seat.LeadCollector.BL;
using Reply.Seat.LeadCollector.UI;
using System.Threading;

namespace Reply.Seat.LeadCollector.iPad
{
	public partial class NuovoViewController : UIViewController
	{
		#region Constructors

		// The IntPtr and initWithCoder constructors are required for controllers that need 
		// to be able to be created from a xib rather than from managed code

		public NuovoViewController (IntPtr handle) : base(handle)
		{
			Initialize ();
		}

		[Export("initWithCoder:")]
		public NuovoViewController (NSCoder coder) : base(coder)
		{
			Initialize ();
		}

		public NuovoViewController () : base("NuovoViewController", null)
		{
			Initialize ();
		}

		void Initialize ()
		{
		}
		
		public NuovoViewController (Lead lead) : this()
		{
			this.nomeTxt.Text = lead.Nome;
			this.cognomeTxt.Text = lead.Cognome;
			this.emailTxt.Text = lead.IndirizzoEmail;
			this.numeroTelefonoTxt.Text = lead.NumeroTelefono;
			this.salvaBtn.Hidden = true;
		}
		
		#endregion
		
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			this.salvaBtn.TouchDown += HandleSalvaBtnhandleTouchDown;
			this.nomeTxt.ShouldReturn = SharedCode.NuovoViewController.DoReturn;
			this.cognomeTxt.ShouldReturn = SharedCode.NuovoViewController.DoReturn;
			this.numeroTelefonoTxt.ShouldReturn = SharedCode.NuovoViewController.DoReturn;
			this.emailTxt.ShouldReturn = SharedCode.NuovoViewController.DoReturn;
			SharedCode.OnUpdateBadge +=  HandleSharedCodeOnUpdateBadge; 
		}
		void HandleSharedCodeOnUpdateBadge (object sender, EventArgs e)
		{
			((AppDelegate)UIApplication.SharedApplication.Delegate).UpdateNonSincronizzatiBadge ();
			
		}
		void HandleSalvaBtnhandleTouchDown (object sender, EventArgs e)
		{
			SharedCode.NuovoViewController.HandleSalvaBtnhandleTouchDown(this,this.waitView,this.nomeTxt.Text,this.cognomeTxt.Text,this.numeroTelefonoTxt.Text,this.emailTxt.Text);
		}
		
	}
}

